package com.glory.erp.invoice.store.dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.glory.erp.invoice.store.dao.StoreDao;
import com.glory.erp.invoice.store.bean.Store;
import com.glory.erp.invoice.store.bean.StoreQuery;
import com.glory.erp.auth.base.BaseDaoImpl;
import com.glory.erp.auth.base.BaseQueryModel;
import com.glory.erp.auth.emp.bean.Emp;

public class StoreDaoImpl extends BaseDaoImpl<Store> implements StoreDao {

	public void doQbc(DetachedCriteria dc, BaseQueryModel qm) {
		StoreQuery sqm = (StoreQuery) qm;
		if (sqm.getName() != null && sqm.getName().trim().length() > 0) {
			dc.add(Restrictions.like("name", "%" + sqm.getName().trim() + "%"));
		}
		if (sqm.getEmp() != null && sqm.getEmp().getUuid() != null
				&& sqm.getEmp().getUuid() != -1) {
			dc.add(Restrictions.eq("emp", sqm.getEmp()));
		}
	}

	public List<Emp> findByEmpName() {
		/*
		 * SELECT DISTINCT e.`name` FROM emp e,store s WHERE
		 * e.`uuid`=s.`empUuid`
		 */
		String hql = "select DISTINCT e.uuid,e.name from Emp e,Store s where e.uuid = s.emp.uuid";
		return this.getHibernateTemplate().find(hql);
	}
}